<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 86166
  Date: 2023/4/3
  Time: 16:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%request.setAttribute("url","http://localhost:8080//OrderingFoodForWebMaven/");%>
<c:set var="ctx" value="<%=request.getContextPath()%>"></c:set>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<html>
<head>
    <title>商家列表</title>
    <style>
        body{
            background-color: #1a81e0;
        }
        #nav{
            background-color: antiquewhite;
            list-style: none;

        }
        #nav li{
            float: right;
            padding: 10px;
        }
        #nav li a{
            line-height: 30px;
            color: black;
            font-size: 14px;
            text-decoration: none;
        }
        #nav li a:hover{
            color: coral;
        }
        #reload{
            position: absolute;
            left: 10px;
        }
        table{
            border: 1px solid black;
            width: 100%;
            background-color: lightsteelblue;
        }
        th,td{
            border-bottom: 1px solid black;
            text-align: center;
        }
        tfoot td{
            border: none;
            background-color: white;
        }
    </style>
    <script>
        function reload(){
            window.location.reload();
        }
    </script>
</head>
<body>
   <div id="container">

        <ul id="nav">
            <li>
                <a href="register.jsp">商家注册</a>

            </li>
            <li>
                <a href="login.jsp">商家登录</a>

            </li>
        </ul>
       <button onclick="reload()" id="reload">刷新</button>

    <table cellspacing="0">
        <thead>
        <tr>
            <th>商家id</th>
            <th>商家名字</th>
            <th>所在省</th>
            <th>所在市</th>
            <th>所在县</th>
            <th>所在详细地址</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="merchant" items="${merchantInfos}">
            <tr>
                <td>${merchant.merchantId}</td>
                <td>${merchant.merchantName}</td>
                <td>${merchant.merchantProvince}</td>
                <td>${merchant.merchantCity}</td>
                <td>${merchant.merchantCounty}</td>
                <td>${merchant.merchantDetailAddress}</td>
            </tr>
        </c:forEach>
        </tbody>
        <form action=""></form>
        <tfoot>
        <tr>
            <td></td>
            <td colspan="4"><button onclick="lastPage(${pageIndex})">上一页</button>
                <input type="text" name="jumpTo" id="jumpTo" placeholder="请输入要跳转的页码" style="width: 50px" onblur="jumpToPage(${pageIndex},${pageCount})">
                <button onclick="nextPage(${pageIndex},${pageCount})">下一页</button>
            </td>

            <td>当前页：${pageIndex} 总页数：${pageCount}</td>

        </tr>
        </tfoot>
    </table>
       
   </div>

</body>
<script>
    function  nextPage(pageIndex,pageCount){
        if (pageIndex >= pageCount){

        }else {
            pageIndex++;
        }
        var url = "http://localhost:8080/OrderingFoodForWeb/bussinessShow.do?pageIndex="+pageIndex;
        location.href=url;
    }
    function  lastPage(pageIndex){
        if (pageIndex <= 1){

        }else {
            pageIndex--;
        }
        var url = "http://localhost:8080/OrderingFoodForWeb/bussinessShow.do?pageIndex="+pageIndex;
        location.href=url;
    }
    function  jumpToPage(pageIndex,pageCount){
        var pageIndexTemp = document.getElementById("jumpTo").value;
        console.log(pageIndexTemp);
        if (pageIndexTemp >=1 && pageIndexTemp <= pageCount && pageIndexTemp!=""){
            pageIndex = pageIndexTemp;
        }
        var url = "http://localhost:8080/OrderingFoodForWeb/bussinessShow.do?pageIndex="+pageIndex;
        location.href=url;
    }
</script>
</html>
